package com.base.app_core.service.Retrofit;


import java.io.IOException;
import java.util.List;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * Created by xiangheng.song on 2017/3/7.
 */

public class SaveCookiesInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        List<String> cookies = originalResponse.headers("Set-Cookie");
        if (!cookies.isEmpty()) {
            for (String cookie : cookies) {
                String[] pair = cookie.split(";")[0].split("=");
                String key = pair[0], value = pair[1];
//                if(AppConstants.SESSION_KEY.equals(key)){
//                    Preferences.putString(AppConstants.SESSION_KEY, value);
//                }else if(AppConstants.TOKEN_KEY.equals(key)){
//                    Preferences.putString(AppConstants.TOKEN_KEY, value);
//                }
            }
        }
        return originalResponse;
    }
}
